/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.infotypes;

/**
 * <code>VisualObjectInfo</code> is a basic type (abstract) for all visible
 * objects of players (not for coach). 
 */
public abstract class VisualObjectInfo extends Info implements Comparable {
	
	/**
	 * The id of the object.
	 */
	protected int id;

	/**
	 * The distance, in which the object was seen.
	 */
	protected double distance;

	/**
	 * The direction, in which the object was seen.
	 */
	protected double direction;

	/**
	 * <code>VisualObjectInfo</code> constructor Any visual object (line,
	 * flag, ball, player)
	 * 
	 * @param cycle -
	 *            time (of perceiving)
	 * @param iId -
	 *            its id
	 * @param iDistance -
	 *            its relative distance to the sensing agent
	 * @param iDirection -
	 *            its relative direction to the sensing agent
	 */
	public VisualObjectInfo(int cycle, int iId, double iDistance,
			double iDirection) {
		super(cycle);
		this.id = iId;
		this.distance = iDistance;
		this.direction = iDirection;
	}

	/**
	 * <code>getDirection</code>
	 * 
	 * @return Returns the direction.
	 */
	public final double getDirection() {
		return this.direction;
	}

	/**
	 * <code>getDistance</code>
	 * 
	 * @return Returns the distance.
	 */
	public final double getDistance() {
		return this.distance;
	}

	/**
	 * <code>getId</code>
	 * 
	 * @return Returns the id.
	 */
	public final int getId() {
		return this.id;
	}

	/**
	 * <code>compareTo</code> from interface java.lang.Comparable. The
	 * comparison is based on the <code>distance</code> attribute.
	 * 
	 * @param o -
	 *            the Object to be compared
	 * @return negative integer, zero, or a positive integer as this objects
	 *         <code>distance</code> is less than, equal to, or greater than
	 *         <code>distance</code> of the specified object.
	 * @throws ClassCastException
	 *             if the specified object's type prevents it from being
	 *             compared to this Object.
	 */
	public final int compareTo(Object o) throws ClassCastException {
		VisualObjectInfo voi = (VisualObjectInfo) o;
		double dist = voi.getDistance();
		// o greater than this
		if (dist > this.distance) {
			return -1;
		} // end if
		// o less than this
		if (dist < this.distance) {
			return 1;
		} // end if
		// o equals this
		return 0;
	}

	/**
	 * Sets the direction, in which the object was seen.
	 * @param direction
	 */
	public void setDirection(double direction) {
		this.direction = direction;
	}

	/**
	 * Sets the distance, in which the object was seen.
	 * @param distance
	 */
	public void setDistance(double distance) {
		this.distance = distance;
	}
	
	/**
	 * Sets the id of the object (especially necessary for lines and
	 * flags).
	 * @param id
	 */
	public void setId(int id) {
		this.id = id;
	}
}
